package com.dqp.cslggroup.UI;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import androidx.recyclerview.widget.RecyclerView;
import com.dqp.cslggroup.R;
import com.dqp.cslggroup.bean.Calendar;

import java.util.List;


public class CalendarAdapter extends BaseAdapter {
    private List<Calendar> calendars;
    private LayoutInflater inflater;
    private CalendarAdapter calendarAdapter;

    public CalendarAdapter(List<Calendar> calendars, Context context) {
        this.calendars = calendars;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return calendars == null ? 0 : calendars.size();
    }

    @Override
    public Object getItem(int position) {
        return calendars.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.xl_img, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

//        Calendar calendar = (Calendar) getItem(position);
//        byte[] xlone = calendar.getXl_1();
//        byte[] xltwe = calendar.getXl_2();
//        ByteArrayInputStream stream_1 = new ByteArrayInputStream(xlone);
//        ByteArrayInputStream stream_2 = new ByteArrayInputStream(xltwe);
//        holder.img_1.setImageDrawable(Drawable.createFromStream(stream_1, "xlone"));
//        holder.img_2.setImageDrawable(Drawable.createFromStream(stream_2, "xltwe"));
        return convertView;
    }


    class ViewHolder extends RecyclerView.ViewHolder {
        private ImageView img_1, img_2;

        public ViewHolder(View view) {
            super(view);
            img_1 = view.findViewById(R.id.xl_img1);
            img_2 = view.findViewById(R.id.xl_img2);
        }
    }


}
